﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;


namespace IHISCETeim.Web.AgentSys.PWMgr
{
    public partial class AgentPWMacList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "AgentPWMacList";
            }
        }

        protected string ShowAgentName
        {
            get
            {
                return base.User.UserType == 2 ? OUserController.MutlCmpStr(base.User.UserId) : "";

            }
        }

        protected string searchAgentName
        {
            get
            {
                return GetRequestValue<string>("searchAgentName", "");

            }
        }

        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }
        protected string IntoDateFrom
        {
            get
            {
                return GetRequestValue<string>("IntoDateFrom", "");

            }
        }

        protected string IntoDateTo
        {
            get
            {
                string temp = GetRequestValue<string>("IntoDateTo", "");
                if (string.IsNullOrEmpty(IntoDateFrom))
                    return "";
                if (string.IsNullOrEmpty(temp))
                {
                    temp = Convert.ToDateTime(IntoDateFrom).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
                }

                return temp;

            }
        }
        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderfield", "PWUMKID");
            }
        }

        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "DESC");
            }
        }


        protected string GetSqlWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(SerialNumber))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("SerialNumber", QueryOperatorsEnum.包含, SerialNumber);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(ShowAgentName))
            {


                sqlcommonFiled = string.Format("AgentName in {0}", ShowAgentName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(searchAgentName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentName", QueryOperatorsEnum.包含, searchAgentName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (IntoDateFrom != "")
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("IntoDate", QueryOperatorsEnum.范围, IntoDateFrom + "|" + IntoDateTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            return wheresql;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
        protected DataTable sumdt = null;
        protected void DataBind()
        {
            DataTableCollection dtc = AgentPWMacKeepController.AgentPWMacKeep_GetPagination(GetSqlWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataSource = dtc[0];
            this.rpMenu.DataBind();

            sumdt = dtc[1];

           // AddLog(Permission.查看);
        }

        protected virtual string GetShowStr(object _UMKDID,object _showStr, object _KeepHours,object _SerialNumber, object _PWUMKID)
        {
            int UMKDID = 0;
            if (!int.TryParse(_UMKDID.ToString(), out UMKDID))
            {
                return "<a class=\"add\" href=\"PWMgr/AgentPWMacKeepDetailEdit.aspx?Action=add&KeepHours="+ _KeepHours .ToString()+ "&SerialNumber="+ _SerialNumber.ToString()+ "&PWUMKID="+ _PWUMKID.ToString()+ "\" target=\"dialog\" title=\"添加保养记录\" rel=\"UMacKeepDetailAdd\" max=\"false\" mask=\"true\" maxable=\"false\" minable=\"false\" resizable=\"false\" drawable=\"true\" width=\"450\" height=\"450\">保养</a>";
            }
            else
            {
                return "<a class=\"edit\" href=\"PWMgr/AgentPWMacKeepDetailEdit.aspx?Action=update&KeepHours=" + _KeepHours.ToString() + "&SerialNumber=" + _SerialNumber.ToString() + "&PWUMKID=" + _PWUMKID.ToString() + "&UMKDID="+ _UMKDID.ToString() + "\" target=\"dialog\" title=\"修改保养记录\" rel=\"UMacKeepDetailAdd\" max=\"false\" mask=\"true\" maxable=\"false\" minable=\"false\" resizable=\"false\" drawable=\"true\" width=\"450\" height=\"450\">" + _showStr.ToString() + "</a>";
                //return _showStr.ToString();
            }

        }

        protected string GetPer(object x1, object x2)
        {
            if (x1 is DBNull || x2 is DBNull)
                return "0";
            if (x2.ToString() == "0")
                return "0";

            return (Convert.ToDecimal(x1) / Convert.ToDecimal(x2) * 100).ToString("F0");
        }
    }
}